package cn.itcast.service.impl;

import cn.itcast.dao.UserDao;
import cn.itcast.dao.impl.UserDaoImpl;
import cn.itcast.domain.User;
import cn.itcast.service.UserService;
import cn.itcast.utils.MD5Utils;

public class UserServiceImpl implements UserService {


    @Override
    public void register(User user) {
        //需要对密码加密
        //使用MD5
        String password = user.getPassword();
        String md5 = null;
        try {
            md5 = MD5Utils.encodeByMd5(password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        user.setPassword(md5);
        //调用到dao完成注册功能
        UserDao userDao=new UserDaoImpl();
        userDao.register(user);
    }

    @Override
    public User login(User user) {
        String password = user.getPassword();
        String md5=null;
        try {
             md5 = MD5Utils.encodeByMd5(password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        user.setPassword(md5);

        UserDao userDao=new UserDaoImpl();
        User user1=null;


        try {
            user1=userDao.login(user);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return user1;

    }
}
